//
//  PersonSetViewController.m
//  diaoyuren
//
//  Created by Cheng on 16/4/10.
//  Copyright © 2016年 game. All rights reserved.
//

#import "PersonSetViewController.h"
#import "PersonSetCell.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
#import "UIImageView+WebCache.h"
@interface PersonSetViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView *tableview;

@end

@implementation PersonSetViewController

- (IBAction)backAction:(id)sender {

    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    StatusBlack;
    
    self.navigationController.navigationBar.hidden = YES;
    self.app.myTabBar.tabBar.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.frame = [UIScreen mainScreen].bounds;
    self.view.backgroundColor = tabGropBackColor;
    
    
    _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, screen_width, SCREEN_HEIGHT-64) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [_tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [_tableview registerNib:[UINib nibWithNibName:@"PersonSetCell" bundle:nil] forCellReuseIdentifier:@"subCell"];
    [self.view addSubview:_tableview];
    
    _tableview.tableFooterView = [UIView new];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 50;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    
    NSArray *ary = @[@"打分支持钓鱼人",@"特别鸣谢",@"清理缓存"];
    
    
    if (indexPath.row<2) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        
        cell.textLabel.text = ary[indexPath.row];
        
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
      
        cell.textLabel.text = ary[indexPath.row];
        
        return cell;

    }else{
    
        PersonSetCell *cell = [tableView dequeueReusableCellWithIdentifier:@"subCell"];
    
        cell.title.text = ary[indexPath.row];
        
        if (indexPath.row==2) {
            
            float tmpSize = [[SDImageCache sharedImageCache] checkTmpSize];
            
            NSString *clearCacheName = tmpSize >= 1 ? [NSString stringWithFormat:@"%.2fM",tmpSize] : [NSString stringWithFormat:@"%.2fK",tmpSize * 1024];
            cell.sunTitle.text = clearCacheName;
        }else{
            cell.sunTitle.text = @"当前版本V1.2";
        
        }
        
        return cell;
    }
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    if (indexPath.row==0) {//跳转打分
        
        NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/idxxxxxxx"];
        
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

    }
    
    if (indexPath.row==1) {//特别鸣谢
        
       
    
    }

    if (indexPath.row==2) {//清理缓存
        
        UIAlertController *alert = [self ShowAlertWhthTitle:@"提示" Message:@"您确定清除所有缓存数据吗？" CancelButtonTitle:@"取消"];
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
             [[SDImageCache sharedImageCache] clearDisk];
            [[SDImageCache sharedImageCache] cleanDisk];
            [[SDImageCache sharedImageCache] clearMemory];
            
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                PersonSetCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                float tmpSize = [[SDImageCache sharedImageCache] checkTmpSize];
                
                NSString *clearCacheName = tmpSize >= 1 ? [NSString stringWithFormat:@"%.2fM",tmpSize] : [NSString stringWithFormat:@"%.2fK",tmpSize * 1024];
                cell.sunTitle.text = clearCacheName;
            });
        }];
        
            [alert addAction:cancel];
    }
}


@end
